package cn.tedu.ykmall.admin.commodity.webapi.controller;

import cn.tedu.ykmall.admin.commodity.service.ICommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("/commodity")
public class CommodityController {
    @Autowired
    private ICommodityService service;

    /**
     * 添加图片并保存在指定路径
     * @param multipartFile
     * @return
     */
    @RequestMapping("/upload")
    public String upload(MultipartFile multipartFile){
        String upload = null;
        try {
            upload = service.upload(multipartFile);

        } catch (IOException e) {
            e.printStackTrace();
        }
        return upload;
    }

    /**
     * 删除图片并将保存在指定路径的图片删除
     * @param name
     */
    @RequestMapping("/remove")
    public void remove(String name){
        service.remove(name);
    }
}
